<template>
  <view>
    <!-- 子组件,收货地址的 -->
    <my-address></my-address>
    <view class="empty-cart" v-if="getCartList.length === 0">
      <image
        class="empty-img "
        src="/static/cart_empty@2x.png"
        mode="scaleToFill"
      />
      <text class="tip-text">空空如也...</text>
    </view>
    <!--  -->
    <view class="cart-container" v-else>
      <view class="cart-title">
        <uni-icons type="cart-filled" :size="18"></uni-icons>
        <text class="cart-title-text">凌凌漆购物车</text>
      </view>
      <!-- 使用子组件,组件最大的作用,就是复用 -->
      <!-- isShowRadio="true"在购物车页面才显示radio标签的样式 -->
      <!-- @radio-change="radiochange"监听子组件传递的数据 -->
      <!-- @uni-number="uninumber"监听子组件传递的数据 -->
      <!-- uni-swipe-action 滑动操作  -->
      <uni-swipe-action>
        <uni-swipe-action-item
          :right-options="options"
          @click="clickdelete(item.goods_id)"
          v-for="item in getCartList"
          :key="item.goods_id"
        >
          <my-goods
            isShowRadio="true"
            isShowNumber="true"
            :goods="item"
            @radio-change="radiochange"
            @uni-number="uninumber"
          ></my-goods>
        </uni-swipe-action-item>
      </uni-swipe-action>
    </view>
    <!-- my-settle 购物车,结算的子组件 -->
    <my-settle></my-settle>
  </view>
</template>
<script>
import badgeMix from '../../mixins/tabbar-badge.js'
import { mapGetters, mapMutations } from 'vuex'
export default {
  mixins: [badgeMix],
  data () {
    return {
      options: [
        {
          text: '删除',
          style: {
            backgroundColor: '#ee2500'
          }
        }
      ]
    }
  },
  computed: {
    ...mapGetters('cart', ['getCartList'])
  },
  methods: {
    ...mapMutations('cart', [
      'updateGoodsState',
      'updateGoodsNumber',
      'deleteGoodsById'
    ]),
    // @radio-change="radiochange"监听子组件传递的数据
    // 1,这里需要调用仓库中的某个方法,去修改仓库中的值,并且把goods这个数据传递过去
    // (所以需要在store\modules\cart.js里面写好对应的逻辑)比如,updateGoodsState
    // 最终会保存在本地,在控制台的Storage中可以看到
    radiochange (goods) {
      console.log('购物车页面打印', goods)
      this.updateGoodsState(goods)
    },
    // @uni-number="uninumber"监听子组件传递的数据
    uninumber (goods) {
      console.log('购物车页面打印Number', goods)

      this.updateGoodsNumber(goods)
    },
    // 删除商品 uni-swipe-action 滑动操作
    clickdelete (goods_id) {
      console.log('goods_id', goods_id)
      this.deleteGoodsById(goods_id)
    }
  }
}
</script>

<style lang="scss" scoped>
.cart-container {
  padding-bottom: 50px;
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;
    .cart-title-text {
      margin-left: 10px;
    }
  }
}
.empty-cart {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;

  .empty-img {
    width: 180rpx;
    height: 180rpx;
  }

  .tip-text {
    font-size: 12px;
    color: gray;
    margin-top: 15px;
  }
}
</style>
